package com.ruoyi.develop.factory.factoryProduceSaleAll.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
        import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import javax.annotation.Resource;

import com.ruoyi.constants.BusinessConstants;
import com.ruoyi.develop.factory.factoryProduceMain.service.IFactoryProduceMainService;
import com.ruoyi.develop.factory.factoryProduceSale.domain.FactoryProduceSale;
import com.ruoyi.develop.factory.factoryProduceSale.service.IFactoryProduceSaleService;
import com.ruoyi.develop.goodsOrderIn.domain.GoodsOrderIn;
import com.ruoyi.develop.goodsSale.domain.GoodsSale;
import com.ruoyi.develop.goodsSaledo.domain.GoodsSaledo;
import com.ruoyi.develop.goodsSaledo.service.IGoodsSaledoService;
import com.ruoyi.develop.goodsSaledoGongxu.service.IGoodsSaledoGongxuService;
import com.ruoyi.develop.goodsSaledoGongxuUser.domain.GoodsSaledoGongxuUser;
import com.ruoyi.develop.goodsSaledoGongxuUser.service.IGoodsSaledoGongxuUserService;
import com.ruoyi.develop.goodsSaledoGongxuUserMoney.service.IGoodsSaledoGongxuUserMoneyService;
import com.ruoyi.develop.lvRuku.service.ILvRukuService;
import com.ruoyi.develop.lvRukumingxi.domain.LvRukumingxi;
import com.ruoyi.develop.lvRukumingxi.service.ILvRukumingxiService;
import com.ruoyi.develop.project.domain.Project;
import com.ruoyi.develop.projectBaseInfo.domain.ProjectBaseInfo;
import com.ruoyi.develop.projectBaseInfo.service.IProjectBaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.develop.factory.factoryProduceSaleAll.mapper.FactoryProduceSaleAllMapper;
import com.ruoyi.develop.factory.factoryProduceSaleAll.domain.FactoryProduceSaleAll;
import com.ruoyi.develop.factory.factoryProduceSaleAll.service.IFactoryProduceSaleAllService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 生产订单和产品合计关联Service业务层处理
 * @author lmm
 * @date 2025-05-08
 */
@Service
public class FactoryProduceSaleAllServiceImpl implements IFactoryProduceSaleAllService {
    @Resource
    private FactoryProduceSaleAllMapper factoryProduceSaleAllMapper;
    @Resource
    private IFactoryProduceSaleService iFactoryProduceSaleService;
    @Resource
    private IProjectBaseInfoService projectBaseInfoService;
    @Resource
    private IGoodsSaledoService iGoodsSaledoService;
    @Autowired
    private ILvRukuService lvRukuService;
    @Autowired
    private ILvRukumingxiService lvRukumingxiService;
    @Autowired
    private IGoodsSaledoGongxuService iGoodsSaledoGongxuService;
    @Autowired
    private IGoodsSaledoGongxuUserService iGoodsSaledoGongxuUserService;
    @Autowired
    private IGoodsSaledoGongxuUserMoneyService iGoodsSaledoGongxuUserMoneyService;
    @Resource
    private IFactoryProduceMainService iFactoryProduceMainService;
    /**
     * 查询生产订单和产品合计关联
     * @param id 生产订单和产品合计关联主键
     * @return 生产订单和产品合计关联
     */
    @Override
    public FactoryProduceSaleAll selectById(String id) {
        return factoryProduceSaleAllMapper.selectById(id);
    }

    /**
     * 查询生产订单和产品合计关联列表
     * @param entity 生产订单和产品合计关联
     * @return 生产订单和产品合计关联
     */
    @Override
    public List<FactoryProduceSaleAll> selectList(FactoryProduceSaleAll entity) {
        return factoryProduceSaleAllMapper.selectList(entity);
    }
    @Override
    public List<FactoryProduceSaleAll> listByChild(FactoryProduceSaleAll entity) {
        return factoryProduceSaleAllMapper.listByChild(entity);
    }

    @Override
    public List<FactoryProduceSaleAll> listFinishDoFactory(FactoryProduceSaleAll entity) {
        return factoryProduceSaleAllMapper.listFinishDoFactory(entity);
    }
    /**
     * 新增生产订单和产品合计关联
     * @param entity 生产订单和产品合计关联
     * @return 结果
     */
    @Override
    public int insert(FactoryProduceSaleAll entity) {
        if(StringUtils.isBlank(entity.getId())){
            entity.setId(IdUtils.fastSimpleUUID());
        }
                entity.setCreateBy(SecurityUtils.getUsername());
                entity.setCreateTime(DateUtils.getNowDate());
            return factoryProduceSaleAllMapper.insert(entity);
    }

    @Override
    public void insertTodo(FactoryProduceSaleAll goodsSaledoList) {
        List<GoodsSaledo> rows = goodsSaledoList.getColumns();
        if (!rows.isEmpty()) {
            for (GoodsSaledo entity : rows) {
                GoodsSaledo goodsSaledo=iGoodsSaledoService.selectById(entity.getId());
                if (goodsSaledo!=null) {
                    FactoryProduceSaleAll factoryProduceSaleAllByGoods = factoryProduceSaleAllMapper.selectByGoodsAndStatusAndRemark(entity.getGoodsId(), entity.getRemark(),goodsSaledoList.getType());
                    ProjectBaseInfo projectBaseInfo = new ProjectBaseInfo();
                    if (StringUtils.isNotBlank(entity.getProjectId())) {
                        projectBaseInfo = projectBaseInfoService.selectById(entity.getProjectId());
                    }
                    if (factoryProduceSaleAllByGoods != null) {
                        if (factoryProduceSaleAllByGoods.getSaleId().contains(entity.getGoodsSaleId())) {

                        } else {
                            factoryProduceSaleAllByGoods.setSaleId(factoryProduceSaleAllByGoods.getSaleId() + "&" + entity.getGoodsSaleId());
                        }
                        if (factoryProduceSaleAllByGoods.getNos().contains(entity.getNos())) {

                        } else {
                            factoryProduceSaleAllByGoods.setQinggouId(factoryProduceSaleAllByGoods.getQinggouId() + "&" + entity.getMainId());
                            factoryProduceSaleAllByGoods.setNos(factoryProduceSaleAllByGoods.getNos() + "&" + entity.getNos());
                        }
                        if (entity.getSaleDate() != null && factoryProduceSaleAllByGoods.getSaleDate() != null) {
                            if (factoryProduceSaleAllByGoods.getSaleDate().compareTo(entity.getSaleDate()) < 0) {
                                factoryProduceSaleAllByGoods.setSaleDate(entity.getSaleDate());
                            }
                        }
                        if (factoryProduceSaleAllByGoods.getProjectId().contains(entity.getProjectId())) {

                        } else {
                            factoryProduceSaleAllByGoods.setProjectId(factoryProduceSaleAllByGoods.getProjectId() + "&" + entity.getProjectId());
                            factoryProduceSaleAllByGoods.setProjectNo(factoryProduceSaleAllByGoods.getProjectNo() + "&" + entity.getProjectNo());
                        }
                        if (projectBaseInfo != null) {
                            if (factoryProduceSaleAllByGoods.getCaigouId().contains(projectBaseInfo.getProjectId())) {

                            } else {
                                factoryProduceSaleAllByGoods.setCaigouId(factoryProduceSaleAllByGoods.getCaigouId() + "&" + projectBaseInfo.getProjectId());
                            }
                        }
                        factoryProduceSaleAllByGoods.setCount(factoryProduceSaleAllByGoods.getCount().add(entity.getPleaseBuyCount()));
                        factoryProduceSaleAllByGoods.setType(goodsSaledoList.getType());
                        update(factoryProduceSaleAllByGoods);
                    } else {
                        factoryProduceSaleAllByGoods = new FactoryProduceSaleAll();
                        factoryProduceSaleAllByGoods.setRemark(entity.getRemark());
                        factoryProduceSaleAllByGoods.setSaleId(entity.getGoodsSaleId());
                        if (projectBaseInfo != null) {
                            factoryProduceSaleAllByGoods.setCaigouId(projectBaseInfo.getProjectId());
                        }
                        factoryProduceSaleAllByGoods.setCount(entity.getPleaseBuyCount());
                        factoryProduceSaleAllByGoods.setCode(entity.getGoodsCode());
                        factoryProduceSaleAllByGoods.setName(entity.getGoodsName());
                        factoryProduceSaleAllByGoods.setXinghao(entity.getGoodModel());
                        factoryProduceSaleAllByGoods.setMiaoshu(entity.getRemark());
                        factoryProduceSaleAllByGoods.setGoodsId(entity.getGoodsId());
                        //factoryProduceSaleAllByGoods.setProduceId();//生产单id
                        factoryProduceSaleAllByGoods.setProjectId(entity.getProjectId());
                        factoryProduceSaleAllByGoods.setProjectNo(entity.getProjectNo());
                        factoryProduceSaleAllByGoods.setQinggouId(entity.getId());
                        factoryProduceSaleAllByGoods.setNos(entity.getNos());
                        factoryProduceSaleAllByGoods.setSaleDate(entity.getSaleDate());
                        factoryProduceSaleAllByGoods.setGongchengName(entity.getGongchengName());
                        factoryProduceSaleAllByGoods.setCustomName(entity.getCustomerName());
                        factoryProduceSaleAllByGoods.setType(goodsSaledoList.getType());
                        //factoryProduceSaleAllByGoods.setStatus("1");
                        insert(factoryProduceSaleAllByGoods);
                    }
                    FactoryProduceSale factoryProduceSale = new FactoryProduceSale();
                    factoryProduceSale.setRemark(entity.getRemark());
                    factoryProduceSale.setSaleId(entity.getGoodsSaleId());
                    if (projectBaseInfo != null) {
                        factoryProduceSale.setCaigouId(projectBaseInfo.getProjectId());
                    }
                    factoryProduceSale.setCount(entity.getPleaseBuyCount());
                    factoryProduceSale.setCode(entity.getGoodsCode());
                    factoryProduceSale.setName(entity.getGoodsName());
                    factoryProduceSale.setXinghao(entity.getGoodModel());
                    factoryProduceSale.setMiaoshu(entity.getRemark());
                    factoryProduceSale.setGoodsId(entity.getGoodsId());
                    //factoryProduceSaleAllByGoods.setProduceId();//生产单id
                    factoryProduceSale.setProjectId(entity.getProjectId());
                    factoryProduceSale.setProjectNo(entity.getProjectNo());
                    factoryProduceSale.setQinggouId(entity.getId());
                    factoryProduceSale.setNos(entity.getNos());
                    factoryProduceSale.setSaleDate(entity.getSaleDate());
                    factoryProduceSale.setGongchengName(entity.getGongchengName());
                    factoryProduceSale.setCustomName(entity.getCustomerName());
                    factoryProduceSale.setParentId(factoryProduceSaleAllByGoods.getId());
                    iFactoryProduceSaleService.insert(factoryProduceSale);
                    entity.setProdstatus(BusinessConstants.PROD_STATUS_1);
                    iGoodsSaledoService.update(entity);
                } else {

                }
            }
        }
    }

    @Override
    public void insertTodoOther(FactoryProduceSaleAll goodsSaledoList) {
        List<GoodsOrderIn> rows = goodsSaledoList.getColumnsOther();
        if (!rows.isEmpty()) {
            for (GoodsOrderIn entity : rows) {
                FactoryProduceSaleAll factoryProduceSaleAllByGoods=factoryProduceSaleAllMapper.selectByGoodsAndStatusAndRemark(entity.getId(),entity.getRemark(),goodsSaledoList.getType());
                if(factoryProduceSaleAllByGoods!=null){
                    if(factoryProduceSaleAllByGoods.getSaleId().contains(entity.getId())){

                    }else{
                        factoryProduceSaleAllByGoods.setSaleId(factoryProduceSaleAllByGoods.getSaleId() + "&" + entity.getId());
                    }
                    if(entity.getSaleDate()!=null && factoryProduceSaleAllByGoods.getSaleDate()!=null){
                        if(factoryProduceSaleAllByGoods.getSaleDate().compareTo(entity.getSaleDate())<0){
                            factoryProduceSaleAllByGoods.setSaleDate(entity.getSaleDate());
                        }
                    }
                    factoryProduceSaleAllByGoods.setCount(factoryProduceSaleAllByGoods.getCount().add(entity.getCount()));
                    factoryProduceSaleAllByGoods.setType(goodsSaledoList.getType());
                    update(factoryProduceSaleAllByGoods);
                }else{
                    factoryProduceSaleAllByGoods = new FactoryProduceSaleAll();
                    factoryProduceSaleAllByGoods.setRemark(entity.getRemark());
                    factoryProduceSaleAllByGoods.setSaleId(entity.getId());
                    factoryProduceSaleAllByGoods.setCount(entity.getCounts());
                    factoryProduceSaleAllByGoods.setCode(entity.getCode());
                    factoryProduceSaleAllByGoods.setName(entity.getName());
                    factoryProduceSaleAllByGoods.setXinghao(entity.getModel());
                    factoryProduceSaleAllByGoods.setMiaoshu(entity.getRemark());
                    factoryProduceSaleAllByGoods.setGoodsId(entity.getId());
                    //factoryProduceSaleAllByGoods.setProduceId();//生产单id
                    //factoryProduceSaleAllByGoods.setQinggouId(entity.getId());
                    factoryProduceSaleAllByGoods.setSaleDate(entity.getSaleDate());
                    factoryProduceSaleAllByGoods.setGongchengName(entity.getGongchengName());
                    factoryProduceSaleAllByGoods.setCustomName("库存");
                    factoryProduceSaleAllByGoods.setType(goodsSaledoList.getType());
                    insert(factoryProduceSaleAllByGoods);

                }

                FactoryProduceSale factoryProduceSale = new FactoryProduceSale();
                factoryProduceSale.setRemark(entity.getRemark());
                factoryProduceSale.setSaleId(entity.getId());
                factoryProduceSale.setCount(entity.getCounts());
                factoryProduceSale.setCode(entity.getCode());
                factoryProduceSale.setName(entity.getName());
                factoryProduceSale.setXinghao(entity.getModel());
                factoryProduceSale.setMiaoshu(entity.getRemark());
                factoryProduceSale.setGoodsId(entity.getId());
                //factoryProduceSaleAllByGoods.setProduceId();//生产单id
                factoryProduceSale.setQinggouId(entity.getId());
                factoryProduceSale.setSaleDate(entity.getSaleDate());
                factoryProduceSale.setGongchengName(entity.getGongchengName());
                factoryProduceSale.setCustomName("库存");
                factoryProduceSale.setParentId(factoryProduceSaleAllByGoods.getId());
                iFactoryProduceSaleService.insert(factoryProduceSale);
            }
        }
    }
    /**
     * 修改生产订单和产品合计关联
     * @param entity 生产订单和产品合计关联
     * @return 结果
     */
    @Override
    public int update(FactoryProduceSaleAll entity) {
                entity.setUpdateBy(SecurityUtils.getUsername());
                entity.setUpdateTime(DateUtils.getNowDate());
        return factoryProduceSaleAllMapper.update(entity);
    }

    @Override
    public int editNotZizhi(FactoryProduceSaleAll entity) {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setStatus(BusinessConstants.PROD_STATUS_9);
        entity.setRemark(SecurityUtils.getUsername()+" 于 "+DateUtils.getNowDate()+"更改为非自制！");
        iFactoryProduceSaleService.updateStatusByParentId(BusinessConstants.PROD_STATUS_9, entity.getId());

        iGoodsSaledoGongxuService.updateStatusByParentId(BusinessConstants.PROD_STATUS_9, entity.getId());
        GoodsSaledoGongxuUser goodsSaledoGongxuUser=new GoodsSaledoGongxuUser();
        goodsSaledoGongxuUser.setSaleId(entity.getId());
        List<GoodsSaledoGongxuUser> goodsSaledoGongxuUserlist=iGoodsSaledoGongxuUserService.selectList(goodsSaledoGongxuUser);
        if(goodsSaledoGongxuUserlist.size()>0){
            for(GoodsSaledoGongxuUser goodsSaledoGongxuUser1:goodsSaledoGongxuUserlist){
                iGoodsSaledoGongxuUserMoneyService.updateStatusByParentId(BusinessConstants.PROD_STATUS_9, goodsSaledoGongxuUser1.getId());
            }
        }
        iGoodsSaledoGongxuUserService.updateStatusByParentId(BusinessConstants.PROD_STATUS_9, entity.getId());
        return factoryProduceSaleAllMapper.update(entity);
    }
    /**
     * 批量删除生产订单和产品合计关联
     * @param ids 需要删除的生产订单和产品合计关联主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids) {
        return factoryProduceSaleAllMapper.deleteByIds(ids);
    }

    /**
     * 删除生产订单和产品合计关联信息
     * @param id 生产订单和产品合计关联主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return factoryProduceSaleAllMapper.deleteById(id);
    }

    @Override
    public int deleteByIdAndChild(String id) {
        List<FactoryProduceSale> factoryProduceSaleList=iFactoryProduceSaleService.selectByParentId(id);
        if(factoryProduceSaleList.size()>0){
            for(FactoryProduceSale factoryProduceSale:factoryProduceSaleList){
                iFactoryProduceSaleService.deleteById(factoryProduceSale.getId());
                if(StringUtils.isNotBlank(factoryProduceSale.getQinggouId())) {
                    GoodsSaledo goodsSaledo = iGoodsSaledoService.selectById(factoryProduceSale.getQinggouId());
                    if(goodsSaledo!=null){
                        goodsSaledo.setProdstatus(BusinessConstants.PROD_STATUS_0);
                        iGoodsSaledoService.update(goodsSaledo);
                    }
                }
            }
        }
        factoryProduceSaleAllMapper.deleteById(id);
        FactoryProduceSaleAll factoryProduceSaleAll=factoryProduceSaleAllMapper.selectById(id);
        List<FactoryProduceSaleAll> factoryProduceSaleAlls=factoryProduceSaleAllMapper.selectByParentId(factoryProduceSaleAll.getProduceId());
        if(factoryProduceSaleAlls.size()<=0){
            iFactoryProduceMainService.deleteById(factoryProduceSaleAll.getProduceId());
        }
        return 1;
    }
    //自制产品提交到质检（入库明细）
    @Override
    @Transactional
    public void insertRukuToZhijianRuku(FactoryProduceSaleAll factoryProduceSaleAll) {
        List<FactoryProduceSaleAll> rows = factoryProduceSaleAll.getColumnsGoodsSaleFactory();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String today = sdf.format(new Date());
        String codeMaxString = lvRukuService.selectMaxCode(today);
        if(StringUtils.isNotBlank(codeMaxString)){
            // 最大编号+1
            codeMaxString = Long.parseLong(codeMaxString)+1+"";
        }else{
            codeMaxString = today+"0001";
        }
        if (!rows.isEmpty()) {
            for (FactoryProduceSaleAll entity : rows) {
                FactoryProduceSaleAll factoryProduceSaleAll1 = factoryProduceSaleAllMapper.selectById(entity.getId());
                factoryProduceSaleAll1.setStatus(BusinessConstants.PROD_STATUS_7);//待质检
                factoryProduceSaleAll1.setRukuCount(factoryProduceSaleAll1.getRukuCount().add(entity.getRukuCount()));
                //goodsSale1.setWeiruCount(goodsSale1.getPleaseBuyCount().subtract(goodsSale1.getRukuCount()));
                factoryProduceSaleAll1.setKerukuCount(factoryProduceSaleAll1.getKerukuCount().subtract(entity.getKerukuCount()));
                factoryProduceSaleAll1.setDaizhijianCount(factoryProduceSaleAll1.getDaizhijianCount().add(entity.getKerukuCount()));
                factoryProduceSaleAllMapper.update(factoryProduceSaleAll1);
                ProjectBaseInfo projectBaseInfo=new ProjectBaseInfo();
                if(factoryProduceSaleAll1.getProjectId()!=null){
                    projectBaseInfo=projectBaseInfoService.selectById(factoryProduceSaleAll1.getProjectId());

                }

                String codeMaxStringMingxi = lvRukumingxiService.selectMaxCode(today);
                if(StringUtils.isNotBlank(codeMaxString)){
                    // 最大编号+1
                    codeMaxStringMingxi = Long.parseLong(codeMaxString)+1+"";
                }else{
                    codeMaxStringMingxi = today+"0001";
                }
                LvRukumingxi lvRukumingxi = new LvRukumingxi();
                //lvRukumingxi.setParentId(lvRuku.getId());//入库单id
                lvRukumingxi.setIsdo(BusinessConstants.STATUS_YES);//自制
                lvRukumingxi.setRemark(factoryProduceSaleAll1.getRemark());
                lvRukumingxi.setFactoryGoodssaleId(factoryProduceSaleAll1.getId());//生产单产品的id
                lvRukumingxi.setFactoryProdNo(factoryProduceSaleAll1.getProduceNo());//生产单的编号
                lvRukumingxi.setFactoryProdId(factoryProduceSaleAll1.getProduceId());//生产单的id
                lvRukumingxi.setGoodsId(factoryProduceSaleAll1.getGoodsId());
                lvRukumingxi.setCode(factoryProduceSaleAll1.getCode());
                lvRukumingxi.setNos(codeMaxStringMingxi);
                lvRukumingxi.setStatus(BusinessConstants.STORAGE_STATE_UN);
                lvRukumingxi.setRukudate(new Date());
                lvRukumingxi.setRukuno(codeMaxString);//入库编号
                lvRukumingxi.setIsZhijian(BusinessConstants.INSPECT_STATE_UN);//
                lvRukumingxi.setRukuren(SecurityUtils.getLoginUser().getUsername());
                if(projectBaseInfo!=null){
                    lvRukumingxi.setCustomerId(projectBaseInfo.getCustomId());
                    lvRukumingxi.setCustomerName(projectBaseInfo.getCustomName());
                    lvRukumingxi.setSaleId(projectBaseInfo.getSaleId());
                    lvRukumingxi.setSaleName(projectBaseInfo.getSalesmanName());
                    lvRukumingxi.setGoodsTotalPrice(projectBaseInfo.getSaleMoney());
                }
                lvRukumingxi.setProjectId(factoryProduceSaleAll1.getProjectId());
                lvRukumingxi.setProjectName(factoryProduceSaleAll1.getGongchengName());
                lvRukumingxi.setProjectNo(factoryProduceSaleAll1.getProjectNo());
                lvRukumingxi.setGoodsType(BusinessConstants.GOODS_TYPE_HARDWARE);//产品类型
                lvRukumingxi.setType(BusinessConstants.TYPE_RUKU);//产品出入库类型

                lvRukumingxi.setDaohuoCount(entity.getKerukuCount());//出入库数量
                lvRukumingxi.setCanCount(entity.getKerukuCount());
                lvRukumingxi.setProductdate(entity.getProductdate());

   /*             lvRukumingxi.setDaohuoCount(entity.getPleaseBuyCount());//出入库数量
                lvRukumingxi.setCanCount(entity.getPleaseBuyCount());
                lvRukumingxi.setDaohuoCount(entity.getYurukuCount());//出入库数量
                lvRukumingxi.setCanCount(entity.getYurukuCount());*/

                lvRukumingxi.setDoremark(entity.getDoremark());
                lvRukumingxi.setDouser(entity.getDouser());
                //lvRukumingxi.setGoodsBuyPrice(lvYifahuomingxi.getDanjian());//发货成本单件
                //lvRukumingxi.setGoodsBuyTotal(lvYifahuomingxi.getMoney());//发货成本总价
                //lvRukumingxi.setGoodsProfit(goodsSale.getGoodsTotalPrice().subtract(lvYifahuomingxi.getMoney()));//利润=销售价-成本
                /*if(BusinessConstants.GOODS_TYPE_MATERIAL.equals(lvYifahuomingxi.getGoodsType())) {
                    lvRukumingxi.setDun(goodsSale.getCount());//到货吨位
                }*/
                lvRukumingxiService.insert(lvRukumingxi);
            }
        }
    }

    //自制产品提交到质检
    @Override
    @Transactional
    public void insertRukuToZhijianFactory(FactoryProduceSaleAll factoryProduceSaleAll) {
        List<FactoryProduceSaleAll> rows = factoryProduceSaleAll.getColumnsGoodsSaleFactory();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String today = sdf.format(new Date());
        String codeMaxString = lvRukuService.selectMaxCode(today);
        if(StringUtils.isNotBlank(codeMaxString)){
            // 最大编号+1
            codeMaxString = Long.parseLong(codeMaxString)+1+"";
        }else{
            codeMaxString = today+"0001";
        }
        if (!rows.isEmpty()) {
            for (FactoryProduceSaleAll entity : rows) {
                FactoryProduceSaleAll factoryProduceSaleAll1 = factoryProduceSaleAllMapper.selectById(entity.getId());
                factoryProduceSaleAll1.setStatus(BusinessConstants.PROD_STATUS_7);//待质检
                factoryProduceSaleAll1.setKerukuCount(factoryProduceSaleAll1.getKerukuCount().subtract(entity.getKerukuCount()));
                factoryProduceSaleAll1.setDaizhijianCount(factoryProduceSaleAll1.getDaizhijianCount().add(entity.getKerukuCount()));
                factoryProduceSaleAllMapper.update(factoryProduceSaleAll1);
            }
        }
    }


    @Override
    public List<FactoryProduceSaleAll> selectHaveNoFinish(String productId) {
        return factoryProduceSaleAllMapper.selectHaveNoFinish(productId);
    }
}

